package com.alipay.demo.trade.service.impl.hb;

import com.alipay.demo.trade.model.hb.SysTradeInfo;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class HbQueue {

   private static Log log = LogFactory.getLog(HbQueue.class);
   public static final int QUEUE_SIZE = 300;
   private static final BlockingQueue queue = new ArrayBlockingQueue(300);


   public static synchronized void offer(SysTradeInfo info) {
      if(info != null) {
         try {
            queue.put(info);
         } catch (InterruptedException var2) {
            log.warn("interrupted for tradeInfo:" + info);
            var2.printStackTrace();
         }
      }

   }

   public static synchronized List poll() {
      if(queue.isEmpty()) {
         return null;
      } else {
         byte size = 30;
         ArrayList tradeInfoList = new ArrayList(size);

         for(int i = 0; i < size; ++i) {
            SysTradeInfo info = (SysTradeInfo)queue.poll();
            if(info == null) {
               break;
            }

            tradeInfoList.add(info);
         }

         return tradeInfoList;
      }
   }
}
